#include "CF_Includes.h"

CCF_Sprite::CCF_Sprite(void)
{
  m_screen.left = 0;
  m_screen.top = 0;
  m_screen.right = 600;
  m_screen.bottom = 600;
}

CCF_Sprite::~CCF_Sprite(void)
{
}

void CCF_Sprite::Initialize( LPDIRECT3DDEVICE9 device )
{
  m_device = device;
  D3DXCreateSprite( m_device, &m_sprite );
}

LPDIRECT3DTEXTURE9 CCF_Sprite::EasyLoad( const LPWSTR filename )
{
  WCHAR fullpath[MAX_PATH];
  GetFullPathName( filename, MAX_PATH, fullpath, NULL );

  D3DXIMAGE_INFO d3dxImageInfo;
  LPDIRECT3DTEXTURE9 result;

  D3DXCreateTextureFromFileEx( m_device,
    fullpath,
    512, 
    512, 
    1,  
    D3DPOOL_DEFAULT,
    D3DFMT_UNKNOWN,
    D3DPOOL_DEFAULT,
    D3DX_DEFAULT,
    D3DX_DEFAULT,
    D3DCOLOR_COLORVALUE(0.0f,0.0f,0.0f,1.0f),
    &d3dxImageInfo,
    NULL,
    &result );

  return result;
}

void CCF_Sprite::Begin()
{
  m_sprite->Begin( D3DXSPRITE_ALPHABLEND );
}

void CCF_Sprite::Draw( LPDIRECT3DTEXTURE9 pTexture, float x, float y, float width, float height )
{
  RECT rect;

  /*rect.left = x;
  rect.top = y;
  rect.right = x + width;
  rect.bottom = y + height;*/

  D3DXVECTOR3 center( width/2, height/2, 0 );
  D3DXVECTOR3 position( x, y, 0 );

  m_sprite->Draw(pTexture, &m_screen, &center, &position, D3DCOLOR_COLORVALUE(1.0f,1.0f,1.0f,1.0f) );
}

void CCF_Sprite::End()
{
  m_sprite->End();
}
